;;;
// my
// my
// my
// my
// my
// my
var form = document.querySelector('form')
var op = document.querySelectorAll('form p')
console.log(op);
for (let i = 0; i <2; i++) {
    op[i].style.visibility = 'hidden'
}
var arr = [false, false]
// 手机号是否正确，并且是否注册了
form.username.onblur = function () {
    var re = /^1[3-9]\d{9}$/
    if (re.test(this.value)) {
        // 验证是否注册
        // 获取本地存储对比  验证是否注册

        if (localStorage.hasOwnProperty("user")) {
            var flag = Y.Storage("user").some(function (item) {
                return item.username == form.username.value
            })
        }
        if (flag) { //注册过
            arr[0] = true
            op[0].style.visibility = "hidden"

        } else {
            arr[0] = false
            op[0].innerHTML = "手机号未注册"
            op[0].style.visibility = "visible"
        }

    } else {
        //手机号不正确
        arr[0] = false
        op[0].innerHTML = "手机号有误"
        op[0].style.visibility = "visible"
    }
}
// 密码是否正确 (手机号正确之后验证密码)
form.psw.onblur = function () {

    if (arr[0]) {
        //判断有没有存储这个值
        if (localStorage.hasOwnProperty("user")) {
            // 验证密码
            var newarr = Y.Storage("user").filter(function (item) {
                return item.username == form.username.value
            })
        }

        //密码是否正确
        if (newarr[0].psw == form.psw.value) {
            arr[1] = true
            op[1].style.visibility = 'hidden'
        } else {
            arr[1] = false
            op[1].innerHTML = '密码错误'
            op[1].style.visibility = 'visible'
        }
    }

}
// 登录
form.onsubmit = function () {

    var flag = arr.every(function (item) {
        return item
    })
    if (flag) {
        // 保存一个状态  证明当前已经登录
        Y.Storage('isLogin', true)
        Y.Storage('logo', "../img1/login/user.png");
        Y.Storage('isLogin', true);
        location.href = '../index.html'
    } else {
        alert('账号或密码错误！')
    }
    return false
}